package org.song.controller;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.song.annotation.RequestTimeRecord;
import org.song.exception.result.AjaxResult;
import org.song.model.dto.ChatLogDto;
import org.song.model.vo.ChatLog;
import org.song.service.ChatLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 博客聊天日志控制层
 */
@Api(tags = "博客聊天日志")
@Controller
@RequestMapping(value = "/chatLog")
public class ChatLogController {

    @Autowired( required = true )
    @Qualifier( value = "chatLogServiceImpl")
    private ChatLogService chatLogService;

    /**
     * 查询所有的博客聊天日志
     * @param chatLogDto
     * @return
     */
    @RequestTimeRecord
    @ApiOperation(value = "查询所有的博客聊天日志" , notes = "查询所有的博客聊天日志")
    @ResponseBody
    @RequestMapping(value = "/listChatLogs" , method = RequestMethod.GET)
    public AjaxResult<List<ChatLog>> listChatLogs(@ApiParam(value = "chatLogDto实例接受查询参数") @NonNull ChatLogDto chatLogDto) {
        PageHelper.startPage(chatLogDto.getPage() , chatLogDto.getSize());
       return AjaxResult.success(chatLogService.listChatLogs(chatLogDto));
    }

    /**
     * 删除博客聊天日志
     * @param chatLog
     * @return
     */
    @RequestTimeRecord
    @ApiOperation(value = "删除博客聊天日志" , notes = "删除博客聊天日志")
    @ResponseBody
    @RequestMapping(value = "/deleteChatLog" , method = RequestMethod.DELETE)
    public AjaxResult<Integer> deleteChatLog(@ApiParam(value = "接受需要删除的博客聊天日志") @NonNull @RequestBody ChatLog chatLog) {
        return AjaxResult.success(chatLogService.deleteChatLog(chatLog));
    }

    /**
     * 增加博客聊天日志
     * @param chatLog
     * @return
     */
    @RequestTimeRecord
    @ApiOperation(value = "增加博客聊天日志" , notes = "增加博客聊天日志")
    @ResponseBody
    @RequestMapping(value = "/insertChatLog" , method = RequestMethod.PUT)
    public AjaxResult<Integer> insertChatLog(@ApiParam(value = "博客聊天日志") @NonNull @RequestBody ChatLog chatLog) {
        return AjaxResult.success(chatLogService.insertChatLog(chatLog));
    }

    /**
     * 更新博客聊天日志
     * @param chatLog
     * @return
     */
    @RequestTimeRecord
    @ApiOperation(value = "更新博客聊天日志" , notes = "更新博客聊天日志")
    @ResponseBody
    @RequestMapping(value = "/updateChatLog" , method = RequestMethod.POST)
    public AjaxResult<Integer> updateChatLog(@ApiParam(value = "根据传入的聊天日志信息进行博客聊天日志更新") @NonNull @RequestBody ChatLog chatLog) {
        return AjaxResult.success(chatLogService.updateChatLog(chatLog));
    }


}
